;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
;;;; Name:          artist.lisp
;;;; Purpose:       Audioscrobbler/lastfm Artist API.
;;;; Programmer:    Nicolas Lamirault <nicolas.lamirault@gmail.com>
;;;;
;;;; This file, part of audioscrobbler, is Copyright (c) 2007 by Nicolas Lamirault
;;;;
;;;; cl-audioscrobbler users are granted the rights to distribute and use this software
;;;; as governed by the terms of the MIT License :
;;;; http://www.opensource.org/licenses/mit-license.php
;;;;
;;;; *************************************************************************


(in-package :cl-audioscrobbler)


(defun retrieve-album-info (artist album)
  "Retrieve information about the ALBUM of ARTIST,
including track listing."
 (get-xml-answer (format nil +album-info+ artist album)))


;; ----------------
;; API WebServices
;; ----------------


(defun get-album-informations (artist album)
  "Get informations about an ALBUM of ARTIST."
  (let ((xmldoc (retrieve-album-info artist album)))
    (when (and (listp (cdr xmldoc))
               (listp (cadr xmldoc)))
      (let ((reach (cadr (first (cdr xmldoc))))
            (url (cadr (second (cdr xmldoc))))
            (release-date (cadr (third (cdr xmldoc))))
            (small (cadr (second (fourth (cdr xmldoc)))))
            (medium (cadr (third (fourth (cdr xmldoc)))))
            (large (cadr (fourth (fourth (cdr xmldoc)))))
            (mbid (cadr (fifth (cdr xmldoc))))
            (tracks 
             (loop for sexp in (cdr (sixth (cdr xmldoc)))
                as track-name = (third (first sexp))
                as track-reach = (second (second sexp))
                as track-url = (second (third sexp))
                collect (make-instance 'track :name track-name
                                              :reach track-reach
                                              :url track-url))))
        (make-instance 'album-infos :name album
                                    :artist-name artist
                                    :release-date release-date
                                    :reach reach
                                    :tracks tracks
                                    :mbid mbid
                                    :url url
                                    :small small :medium medium :large large)))))

